package com.design.twords.adatper;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.design.twords.R;
import com.design.twords.database.Sentence_all;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * Create by Alen
 * Time:  15:27
 */
public class SentenceAdapter extends RecyclerView.Adapter<SentenceAdapter.MyViewHolder>{

    private LayoutInflater myInflater;
    private Context context;
    private List<Sentence_all> sents;
    private int viewId;
    private String booktype;

    public SentenceAdapter(Context context, List<Sentence_all> sents, int viewId, String booktype) {
        this.myInflater = LayoutInflater.from(context);
        this.context = context;
        this.sents = sents;
        this.viewId = viewId;
        this.booktype = booktype;
    }

    public void setSents(List<Sentence_all> sents) {
        this.sents = sents;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyViewHolder(myInflater.inflate(viewId, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        Sentence_all sentence_all = sents.get(position);
        holder.sent_id.setText(String.valueOf(position+1));
        holder.sent_content.setText(sentence_all.getSentence());
        holder.sent_trans.setText(sentence_all.getTran());

    }

    @Override
    public int getItemCount() {
        return sents.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView sent_id, sent_content, sent_trans;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            sent_id = itemView.findViewById(R.id.sentence_id);
            sent_content = itemView.findViewById(R.id.sentence_content);
            sent_trans = itemView.findViewById(R.id.sentence_trans);
        }
    }
}
